home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 7 code / QuickTime / SimpleInMovies / SimpleInPicts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-13  |  6.3 KB  |  228 lines  |  [TEXT/MPS ]

  1. /*     
  2. SimpleInMovies
  3.  
  4. Sample programs demonstrating how to open and display
  5. QuickTime™ Movies.
  6.  
  7. SimpleInPicts.c file contains the code for a couple of procedures that take
  8. care of obtaining and displaying PICTs from a movie.
  9.  
  10. Guillermo A. Ortiz
  11. Macintosh Developer Technical Support
  12. */
  13.  
  14. /* Changes log:
  15.     08/07/91 -- GetMediaHandlerDescription was not happy when receiving a track instead of a media.
  16.     12/03/91 -- Changed the track picture stuff to make it work with final version.
  17.     12/03/91 -- Changed the routine that used to show a picture of the current time, now
  18.                 it sets the poster if non is present.
  19. */
  20. #include <SimpleInMovie.h>
  21.  
  22. #define pictDialog     130
  23. #define aButton        2
  24. #define usrItem        3
  25. #define txtItem        4
  26. #define noPosterAlert 131
  27.  
  28. extern void PrintThis( PicHandle );
  29.  
  30. void DoGet1MoviePict(void);
  31. void DoGetTrackPicts(void);
  32. extern Boolean IsAppWindow(WindowPtr);
  33.  
  34. /* User Item proc, displays a picture in the dialog. */
  35. pascal void myDrawPict(theDialog, itemNumber)
  36. WindowPtr     theDialog;
  37. short        itemNumber;
  38. {
  39. short itemType;
  40. Handle DItem;
  41. Rect      box;
  42. PicHandle theP;
  43.  
  44.     GetDItem(theDialog,itemNumber,&itemType, &DItem, &box);
  45.     if (itemType == userItem) {
  46.       theP = (PicHandle)GetWRefCon(theDialog);
  47.       DrawPicture(theP, &box);
  48.     }
  49. }
  50.  
  51. /* This routine gets the pict representing the current movie time and
  52.    displays it in a dialog. The user can then select if the frame
  53.    should be used as the movie poster.
  54. */
  55. void DoGet1MoviePict()
  56. {
  57. WindowPtr window;
  58. DialogPtr theDialog;
  59. PicHandle moviePict;
  60. short itemType, itemHit;
  61. Handle DItem;
  62. Rect box;
  63. CGrafPtr savePort;
  64. GDHandle saveGDevice;
  65. DocRecHandle    wHndl;
  66. TimeValue moovTime;
  67. TimeRecord moovTRec;
  68. OSErr err;
  69.  
  70.     if (window = FrontWindow()) { /* don't bother if no movies */
  71.       if (IsAppWindow(window) && (wHndl = (DocRecHandle)GetWRefCon(window)) ) {
  72.         GetGWorld(&savePort, &saveGDevice);
  73.         
  74.         theDialog = GetNewDialog(pictDialog,nil, (WindowPtr) -1);
  75.         SetPort(theDialog);
  76.         GetDItem(theDialog,usrItem,&itemType, &DItem, &box);
  77.         if (itemType == userItem) {
  78.           SetDItem(theDialog,usrItem,itemType, (Handle)&myDrawPict, &box);
  79.         }
  80.  
  81.         moovTime = GetMovieTime((*wHndl)->wMovie, &moovTRec);
  82.         moviePict = GetMoviePict((*wHndl)->wMovie,moovTime);
  83.         SetWRefCon(theDialog, (long)moviePict);
  84.         do {
  85.           ModalDialog(nil, &itemHit);
  86.         } while (itemHit != okButton && itemHit != cancelButton);
  87.  
  88.         
  89.         if (itemHit == okButton) { /* set the poster time */
  90.           SetMoviePosterTime((*wHndl)->wMovie, moovTime);
  91.           if (err = GetMoviesError() )
  92.             DebugStr("\perror trying to set poster time"); 
  93.         }
  94.  
  95.         CloseDialog(theDialog);
  96.         KillPicture(moviePict);
  97.         SetGWorld(savePort, saveGDevice);
  98.       }
  99.     }
  100.     return;    
  101. }
  102.  
  103. /* This routine opens a dialog and displays in succession the
  104.    frames of the first video track found in a movie. If the movie
  105.    has no video tracks then the call just returns.
  106.    
  107.    The process used is the following:
  108.    
  109.    1- Get a video track
  110.    2- Get begining and end of track
  111.    3- Call GetTrackNextInterestingTime to scan frames
  112.    4- if time = trackEnd duration time trackBegin
  113.    5- go back to 3 unless ok is clicked
  114.    
  115.    
  116. */
  117.  
  118. #define forwardNormalSpeed 0x00010000        /* normal speed (1) in fixed */
  119. void DoGetTrackPicts()
  120. {
  121. WindowPtr window;
  122. DialogPtr theDialog;
  123. PicHandle moviePict;
  124. short itemType, itemHit;
  125. Handle DItem;
  126. Rect box;
  127. CGrafPtr savePort;
  128. GDHandle saveGDevice;
  129. DocRecHandle    wHndl;
  130. TimeValue inTime, trackEnd, trackOffset;
  131. long trackCount, count;
  132. Track videoTrack = nil;
  133. Str255 creator;
  134. OSType mediaType, manuf;
  135.  
  136.     if (window = FrontWindow()) { /* don't bother if no movies */
  137.       if (IsAppWindow(window) && (wHndl = (DocRecHandle)GetWRefCon(window)) ) {
  138.         GetGWorld(&savePort, &saveGDevice);
  139.  
  140.         trackCount = GetMovieTrackCount((*wHndl)->wMovie); /* how many tracks are there? */
  141.         for (count = 1; count <= trackCount; count++) {
  142.           videoTrack = GetMovieIndTrack((*wHndl)->wMovie,count);
  143.  
  144. /**** The following does not work anymore
  145.           GetMediaHandlerDescription((Media) videoTrack,&mediaType, &creator,&manuf);
  146.       so I am changing it to make it work                                                  */
  147.           GetMediaHandlerDescription(GetTrackMedia(videoTrack),&mediaType, &creator,&manuf);
  148.  
  149.           if (mediaType == 'vide') /* type we are looking for */
  150.             break;
  151.           else
  152.             videoTrack = nil;
  153.         }
  154.         
  155.         if (!videoTrack) return; /* looped through tracks with no luck */
  156.         
  157.         theDialog = GetNewDialog(pictDialog,nil, (WindowPtr) -1);
  158.         SetPort(theDialog);
  159.  
  160.         GetDItem(theDialog,aButton,&itemType, &DItem, &box);
  161.         if (itemType == ctrlItem) {
  162.           SetCTitle((ControlHandle) DItem,"\pNext");
  163.         }
  164.         
  165.         GetDItem(theDialog,txtItem,&itemType, &DItem, &box);
  166.         if (itemType == statText) {
  167.           SetIText(DItem, "Click Next to advance frame.");
  168.         }
  169.         
  170.         GetDItem(theDialog,usrItem,&itemType, &DItem, &box);
  171.         if (itemType == userItem) {
  172.           SetDItem(theDialog,usrItem,itemType, (Handle)&myDrawPict, &box);
  173.         }
  174.         trackEnd = GetTrackDuration(videoTrack);    /* end of track in movie time        */
  175.         trackOffset = GetTrackOffset(videoTrack);         /* begining of track in movie time     */
  176.         inTime = trackOffset;
  177.         
  178.         do {
  179.           moviePict = GetTrackPict(videoTrack,inTime);
  180.           SetWRefCon(theDialog, (long)moviePict);
  181.           InvalRect(&box);
  182.  
  183.           GetTrackNextInterestingTime(videoTrack,nextTimeMediaSample,
  184.                                       inTime, forwardNormalSpeed, &inTime, nil);
  185.           if ( inTime == -1 )         /* when we ask for the next interesting time after the end     */
  186.             inTime = trackOffset;    /* the result is -1; so go to beginning.                    */
  187.             
  188.           ModalDialog(nil, &itemHit);
  189.  
  190.           KillPicture(moviePict);
  191.  
  192.         } while (itemHit != okButton);
  193.  
  194.         CloseDialog(theDialog);
  195.         SetGWorld(savePort, saveGDevice);
  196.       }
  197.     }
  198.     return;    
  199. }
  200.  
  201. /* This routine gets the poster picture and call the code that does the
  202.    actual printing. If no picture is available then it present the user
  203.    with an alert informing of the sad condition.
  204. */
  205. void PrintPoster(void)
  206. {
  207. WindowPtr window;
  208. PicHandle posterPict;
  209. DocRecHandle    wHndl;
  210. short itemHit;
  211.  
  212.     if (window = FrontWindow()) { /* don't bother if no movies */
  213.       if (IsAppWindow(window) && (wHndl = (DocRecHandle)GetWRefCon(window)) ) {
  214.         
  215.         if ( posterPict = GetMoviePosterPict((*wHndl)->wMovie)) {
  216.           PrintThis(posterPict);
  217.           KillPicture(posterPict);
  218.         }
  219.         else { /* Did not get pict bummer! */
  220.           SetCursor(&qd.arrow);
  221.           ParamText((*wHndl)->wFileInfo.sfr.sfFile.name, nil, nil, nil);
  222.           itemHit = StopAlert(noPosterAlert, nil);
  223.         }
  224.       }
  225.     }
  226.     return;    
  227. }
  228.